package logic

import (
	"context"
	"doc-manage/models/mysql"
	"errors"

	"doc-manage/doc/doc"
	"doc-manage/doc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DocShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDocShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocShowLogic {
	return &DocShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *DocShowLogic) DocShow(in *doc.DocShowRequest) (*doc.DocShowResponse, error) {
	// todo: add your logic here and delete this line

	var Doc mysql.Doc
	if err := mysql.DB.Where("id=?", in.DocId).First(&Doc).Error; err != nil {
		return nil, errors.New("当前医生不存在")
	}
	if err := Doc.DocShow(mysql.DB); err != nil {
		return nil, err
	}

	return &doc.DocShowResponse{
		DocId: int64(in.DocId),
		Name:  Doc.Name,
		Image: Doc.Image,
		Area:  Doc.Area,
	}, nil
}
